home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NetNews Offline 2
/
NetNews Offline Volume 2.iso
/
news
/
comp
/
std
/
c
/
620
< prev
next >
Wrap
Internet Message Format
|
1996-08-06
|
1KB
Path: usin.com!rwells
From: rwells@usin.com (Roger Wells)
Newsgroups: comp.std.c
Subject: Re: Restrictions on qsort compare function?
Date: 21 Mar 1996 17:00:46 GMT
Organization: U.S. Intelco Networks, Inc.
Distribution: world
Message-ID: <4is1vu$5et@news1.halcyon.com>
References: <4iokop$h4p@lyra.csx.cam.ac.uk> <4iqjar$2m9@usenet.pa.dec.com>
NNTP-Posting-Host: 198.202.216.7
In article <4iqjar$2m9@usenet.pa.dec.com>, diamond@tbj.dec.com (Norman Diamond) writes:
>In article <4iokop$h4p@lyra.csx.cam.ac.uk>, jkb@mrc-lmb.cam.ac.uk (James Bonfield) writes:
>>Are there any limitations on what the sort function passed over to qsort can
>>do or return?
>
>>I know it's meant to return < 0, 0 or > 0 for the various compare operations,
>>but which you return is purely up to your own comparison system.
>
>Exactly.
>
>>On tracking down a bug in some old code I noticed that we had the
>>compare function returning something like "a > b" instead of "b - a".
>>Now this is obviously some silly bug in our coding,
>
>Actually it's a silly question. Just one sentence earlier, you gave the
>exact reason why it doesn't matter if you do "a > b" instead of "a - b".
The expression a > b can only have the values 0 or 1; therefore, if your
qsort comparison returns a > b it will never return a negative value. If
a is less than b, it will return 0, which to qsort means they are equal. I
do not believe that is what you want.
--
Roger Wells (speaking only for myself)